package cn.qianyan.controllers;

import cn.qianyan.beans.UserRight;
import cn.qianyan.service.MenuManaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:
 * @createDate:
 * @description:
 */
@Controller
@ResponseBody
@RequestMapping("menuMana")
public class MenuManaController {

    @Autowired
    private MenuManaService menuManaService;

    @RequestMapping("updateMenu")//更新一个人权限
    public int updateMenu(@RequestParam("uright") int uright,@RequestParam("user") int user, @RequestParam("menu") int menu,@RequestParam("area") int area,
                          @RequestParam("device") int device, @RequestParam("home") int home){
        UserRight userRight = new UserRight();
        userRight.setUright(uright);
        userRight.setUser(user);
        userRight.setMenu(menu);
        userRight.setArea(area);
        userRight.setDevice(device);
        userRight.setHome(home);
        int i = menuManaService.updateMenu(userRight);
        if(i==0){
            return 0;
        }
        return 10025;
    }

    @RequestMapping("showAll")
    public Map showAll(){//显示所有人权限
        List<UserRight> userRights = menuManaService.showAll();
        Map<Object,Object> rightMap = new HashMap<>();
        if(userRights!=null){
            rightMap.put("code",0);
            rightMap.put("data",userRights);
        }else {
            rightMap.put("code",10024);
        }
        return rightMap;
    }

}
